home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor1 / coder.doc < prev    next >
Text File  |  1995-03-31  |  6KB  |  172 lines

  1. (Comp.sys.handhelds) 
  2. Item: 3696 by Simone.Rapisarda at wolf.sublink.org 
  3. Author: [Simone Rapisarda] 
  4.   Subj: new CODER 
  5.   Date: Tue Jul 16 1991 
  6.  
  7. Sorry but the version of CODER that I posted some days ago doesn't work fine. 
  8. Excuse me if it caused any problem to you.  Here is the correct version and 
  9. this time it's in commented user RPL because of the few 'exercise to the 
  10. reader' of the past days.  :)  Thanks to Jurjen that showed me the problems with 
  11. CODER and that showed me also that is not really impossible to find the key. 
  12.  
  13. --------------- 
  14.  
  15. Do you keep any top-secret data in your 48 ? 
  16.  
  17. If yes, the following program will be very useful to you. 
  18.  
  19.  
  20.                          C O D E R 
  21.                          --------- 
  22.  
  23.                   STRING CODER & DECODER 
  24.  
  25.                    by  Simone Rapisarda 
  26.  
  27. CODER requires two arguments: a string to de/code on level two and  
  28. a cipher key-string on level one. 
  29. If the arguments are not strings CODER will change them into strings  
  30. before coding. 
  31. The two strings can be of any length; the longer the cipher key, the safer 
  32. the result string. If the cipher key-string is longer than the  
  33. string to de/code it will be truncated. 
  34. The algorithm used is very simple. The program is only 60 bytes long.  
  35. The coding of a 1000 characters string with a 5 characters cipher key  
  36. takes about .2 seconds.  
  37.  
  38.  
  39.                                 USAGE 1 
  40.  
  41. |3:                        |             |3:                        |  
  42. |2:        "String to Code"|             |2:                        |  
  43. |1:            "Cipher Key"|    ---->    |1:          "Coded String"|  
  44. |CODER ### ### ### ### ### |             |CODER ### ### ### ### ### |  
  45. +--------------------------+             +--------------------------+ 
  46.  
  47.  
  48.  
  49.                                 USAGE 2 
  50.  
  51. |3:                        |             |3:                        |  
  52. |2:      "String to Decode"|             |2:                        |  
  53. |1:            "Cipher Key"|    ---->    |1:        "Decoded String"|  
  54. |CODER ### ### ### ### ### |             |CODER ### ### ### ### ### |  
  55. +=====---------------------+             +--------------------------+ 
  56.  
  57.  
  58. Here it is. 
  59.  
  60.  
  61. ------8<------8<------- 
  62. %%HP: T(3)A(D)F(.); 
  63. \<< \->STR SWAP \->STR        @  Makes sure the two arguments are strings.  
  64. DUP SIZE ROT                  @  Size of the string to de/code.  
  65. WHILE DUP2 SIZE >             @  Do it until the two sizes are equal.  
  66. REPEAT DUP +                  @  Doubles the length of the key string.  
  67. END 1 ROT SUB XOR             @  Makes sure the two strings are of equal 
  68.  \>>                          @  length then finally code them.  
  69. ------8<------8<------- 
  70.  
  71.  
  72. ciao 
  73.                                                 RAP 
  74.  
  75.  
  76.  
  77.  
  78. --   
  79.  WolfNet BBS Pisa (Italy) Tel. +39-50-589050 300-14.4K Baud Matrix 2:332/602.0 
  80.  Simone Rapisarda - via FidoNet node 2:33/800 
  81.  UUCP: ...!gear!wolf!Simone.Rapisarda 
  82.  ARPA: Simone.Rapisarda@wolf.sublink.org 
  83.  
  84. ---------- 
  85.   Resp: 1 of 1 by cloos at acsu.buffalo.edu 
  86. Author: [James H. Cloos] 
  87.   Date: Tue Jul 16 1991 22:51  
  88.  Lines: 159 
  89.  
  90. Being the (original definition!) hacker type, I tend to rewrite a lot of 
  91. programs I get off the net into internal rpl for my own use.  I thought this 
  92. one might be a good example to show how that is done with the new (NOMAS) 
  93. development system.  Above, you see the userlang version of a simple cipher 
  94. program.  Below is a rpl version, using only the fixed words as described in 
  95. the entries.a file in the development system distribution. 
  96.  
  97. [Note: It is Jim's version that's on this disk.  -jkh-] 
  98.  
  99. **      coder.s 
  100. **      From userlang routine by Simone Rapisarda 
  101.  
  102.     ASSEMBLE 
  103.             NIBASC /HPHP48-D/ 
  104.     RPL 
  105.  
  106.         :: 
  107.           CK2NOLASTWD DO>STR SWAP DO>STR DUPLEN$ ROT 
  108.           BEGIN 2DUP LEN$ #> 
  109.           WHILE DUP &$ 
  110.           REPEAT ONE ROT SUB$ XOR$ 
  111.         ; 
  112.  
  113. Normally, of course, you'd run this thru RPLCOMP, SASM, and SLOAD, but given 
  114. its short size, I found it actually easier to hand compile into the following, 
  115. in ASCI acceptable format (in the latest version of HACKIT, at least): 
  116.  
  117. "D9D20   @ :: 
  118.  D8A81   @ CK2NOLASTWD 
  119.  88041   @ DO>STR 
  120.  32230   @ SWAP 
  121.  88041   @ DO>STR 
  122.  BB726   @ DUPLEN$ 
  123.  59230   @ ROT 
  124.  2A170   @ BEGIN 
  125.  CA130   @ 2DUP 
  126.  63650   @ LEN$ 
  127.  38D30   @ #> 
  128.  EE170   @ WHILE 
  129.   D9D20  @  :: 
  130.   88130  @  DUP 
  131.   3915D  @  &$ 
  132.   B2130  @  ; 
  133.  5E170   @ REPEAT 
  134.  9FF30   @ ONE 
  135.  59230   @ ROT 
  136.  33750   @ SUB$ 
  137.  B9881   @ XOR$ 
  138.  B2130   @ ; 
  139.  
  140. Notice that as only a single object can be between the WHILE and REPEAT, 
  141. the two words I wanted to put there had to be encased in a :: ; pair.  This 
  142. is, of course, done for you by RPLCOMP. 
  143.  
  144. If anyone wants to type this in and use ASC\->, rather than ASCI\->, it 
  145. would look like: 
  146.  
  147. "D9D20D8A81880413223088041BB726592302A170CA1306365038D30EE170D9D2 
  148. 0881303915DB21305E1709FF305923033750B9881B2130B386" 
  149.  
  150. With the systems docs at hand, you shouldn't have any trouble converting 
  151. routines.  Just be sure to do them a small bit at a time.  And also note than 
  152. you can come back, after you have the routines working, and replace things like 
  153.                 DUP LEN$ 
  154. with words like 
  155.                 DUPLEN$ 
  156. that combine those functions; you do not have to worry about them at first. 
  157. Keep a copy of entries.a handy, and you can look up all of your word pairs and 
  158. see if a combo word is available to do that. 
  159.  
  160. As Bill said (@ least I *think* it was he), I [also] hope to see a lot of good, 
  161. interesting programs showing up here. 
  162.  
  163. Happy developing! 
  164.  
  165. -JimC 
  166. -- 
  167. James H. Cloos, Jr.             Phone:  +1 716 673-1250 
  168. cloos@ACSU.Buffalo.EDU          Snail:  PersonalZipCode:  14048-0772, 
  169. USA 
  170. cloos@ub.UUCP                   Quote:  <> 
  171.